<?php defined('SYSPATH') OR die('No direct access allowed.');

class Forum_Comment_Model extends ORM implements Acl_Resource_Interface {

	//protected $db = 'forum';
	protected $belongs_to = array('post'=>'forum_post', 'author'=>'forum_user');
	protected $load_with = array('author');
	protected $ignored_columns = array('captcha');

	public function getComments($id) {
		if (!is_numeric($id))
			return array();
		return $this->where('post_id', $id)->orderby('created', 'ASC')->find_all();
	}

	public function get_by_user($id) {
		return $this->where('author_id', $id)->find_all();
	}

	public function validate(array & $array, $save = FALSE) {
		$array = Validation::factory($array)
			->pre_filter('trim')
			->add_rules('text', 'required');
		if (!Captcha::instance()->promoted())
			$array->add_rules('captcha', 'required', 'Captcha::valid');

		return parent::validate($array, $save);
	}

	public function get_resource_id() {
		return 'forum_comment';
	}

}